package com.evergrande.mybatis.service.impl;

import com.evergrande.mybatis.model.UserInfo;
import com.evergrande.mybatis.service.UserInfoService;
import org.springframework.stereotype.Service;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.codec.digest.DigestUtils;

/**
 * Created by yyccbbz on 2016-8-11.
 */
@Service("userInfoService")
public class UserInfoServiceImpl extends BaseService<UserInfo> implements UserInfoService {


    @Override
    public String login(String username, String password) {
        UserInfo userInfo = new UserInfo();
        userInfo.setUsername(username);
        UserInfo user = mapper.selectOne(userInfo);
        if (!StringUtils.equals(user.getPassword(), DigestUtils.md5Hex(password))) {
            // 登录失败
            return null;
        }
        // 登录成功
        // 生成ticket
        String ticket = DigestUtils.md5Hex(System.currentTimeMillis() + username);
        return ticket;
    }
}
